// Problem: 
// Contest: 
// URL: 
// Memory Limit: 
// Time Limit: 
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int N=998244853;
int qpow(int x,int n)
{
	int ret=1;
	while(n>0)
	{
		if(n%2==1)ret=ret*x%N;
		n/=2;
		x=x*x%N;
	}
	return ret;
}
int qf(int a,int b)
{
	return a*qpow(b,N-2)%N;
}
int n,m;
//double ans;
int ans;
vector<int> a(n+1),b(n+1),c(n+1);
void dfs(int x,int sum,int p)
{
	if(sum%m==0&&x==n)
	{
		ans=ans+p%N;
		return ;
	}
	if(x==n)return ;
	dfs(x+1,sum+a[x+1],p*b[x+1]%N);
	dfs(x+1,sum,p*c[x+1]%N);
}
signed main()
{
	int t=1;
//	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		a=b=c=vector<int>(n+1);
		for(int i=1;i<=n;i++)cin>>a[i];
		for(int i=1;i<=n;i++)
		{
			cin>>b[i];
			c[i]=N+1-b[i];
		}
		dfs(1,a[1],b[1]);
		dfs(1,0,c[1]);
		cout<<ans%N;
		//cout<<qf(29,84);
	}
	return 0;
}
